﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-09-08 15:19:40
 * 功能：开关状态控制
**************************************************************************************/

using UnityEngine;
using UnityEngine.UI;

namespace Game.UI.HallPanel
{
    public class SwitchStatus : MonoBehaviour
    {
        private Toggle m_Switch;
        private RectTransform m_IconRect;
        private MyOutline m_Outline;
        [SerializeField] private Color m_OnColor;
        [SerializeField] private Color m_OffColor;
        private Vector2 m_DefPos;

        private void Awake()
        {
            m_Switch = GetComponent<Toggle>();
            m_IconRect = transform.Find("Icon").GetComponent<RectTransform>();
            m_Outline = transform.Find("Label").GetComponent<MyOutline>();
            m_DefPos = m_IconRect.anchoredPosition;

            m_Switch.onValueChanged.AddListener(OnSwitchValueChanged);
            OnSwitchValueChanged(m_Switch.isOn);
        }

        private void OnSwitchValueChanged(bool isOn)
        {
            m_Outline.OutlineColor = isOn ? m_OnColor : m_OffColor;
            m_IconRect.localScale = Vector3.one * (isOn ? 1.3f : 1f);
            m_IconRect.anchoredPosition = isOn ? new Vector2(0, -20f) : m_DefPos;
        }
    }
}